<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?>
<style>
 
/* Z-index of #mask must lower than #boxes .window */
#mask {
  position:absolute;
  z-index:9000; top:0; left: 0;
  background-color:#000;
  display:none;
}
   
#option3 {
  position:absolute; background: #fff;
  width:300px;
  height:215px;
  display:none;
  z-index:9999;
  padding:20px; border:2px solid #ddd;
}
#pay-mess {text-align:right; color: red}
</style>
<div class="middle myclear">
	<div class="pad10">
			
			<p class="breview-page-title">
				<?php echo $lang['list_banner_appro']?>
			</p>
						
			<form name="frm_breview" method="post" action="">
			<table class="breview-dashboard">
				<tr>
					<td class="label">
						<?php echo $lang['total_banner_appro']?>
					</td>
					<td class="label">
						<?php echo $lang['banner_approved']?>
					</td>
					<td class="label">
						<?php echo $lang['banner_wait_appro']?>
					</td>
				</tr>
				
				<tr>
					<td class="padtop10"><?php echo number_format($sum_all_banner, 0)?></td>
					
					<td class="padtop10"><?php echo number_format($sum_old_banner, 0)?></td>
					
					<td class="padtop10"><?php echo number_format($sum_new_banner, 0)?></td>
				</tr>
			</table>
			
			<table class="marbottom10" >
				<tr>
					<td class="padleft5 bold text-666 ver-middle">
						<?php echo $lang['select']?>
					</td>
					
					<td class="padleft10 ver-middle">
						<select class="breview-filter" id="slcFilter" onchange="slcFilterChange();" >
							<option value="all" <?php echo $filter == 'all' ? 'selected="selected"' : '';?> ><?php echo $lang['select_all']?></option>
							<option value="new" <?php echo $filter == 'new' ? 'selected="selected"' : '';?>><?php echo $lang['create_new']?></option>
							<option value="old" <?php echo $filter == 'old' ? 'selected="selected"' : '';?>><?php echo $lang['b_koduyet']?></option>
							<option value="exi" <?php echo $filter == 'exi' ? 'selected="selected"' : '';?>><?php echo $lang['b_daduyet']?></option>
						</select>
					</td>
					<td class="padleft5 bold text-666 ver-middle">
						<?php echo $lang['publisher']?>
					</td>
					
					<td class="padleft10 ver-middle">
						<select class="breview-filter" id="slcPublisher" onchange="slcFilterChange();" >
							<option value="0"><?php echo $lang['select_all']?></option>
							<?php foreach ($publishers as $pub){?>
							<option value="<?php echo $pub['user_id']?>" <?php if($uid == $pub['user_id']) echo 'selected="selected"';?>><?php echo $pub['username']?></option>
							<?php }?>
						</select>
					</td>
				</tr>
			</table>
			
			<table class="tbl-list" width="100%" border="1">
				<tr>
					<td class="td-label text-center">
						<p><strong><?php echo $lang['stt']?></strong></p>
					</td>
					
					<td class="td-label" >
						<p><strong><?php echo $lang['b_image']?></strong></p>
					</td>
					
					<td class="td-label" >
						<p><strong><?php echo $lang['b_title']?></strong></p>
					</td>
					
					<td class="td-label" >
						<p><strong><?php echo $lang['b_content']?></strong></p>
					</td>
					
					<td class="td-label" >
						<p><strong><?php echo $lang['b_url']?></strong></p>
					</td>
					
					<td class="td-label" >
						<p><strong><?php echo $lang['b_campaign']?></strong></p>
					</td>
					
					<td class="td-label" >
						<p><strong><?php echo $lang['b_author']?></strong></p>
					</td>
					
					<td class="td-label">
						<p><strong><?php echo $lang['b_status']?></strong></p>
					</td>
					
					<td class="td-label text-center">
						<p><input type="checkbox" id="chkAll" onclick="chkReviewChange();" /></p>
					</td>
				</tr>
				
				<?php for($i = 0; $i < count($lstBanner); $i++){
					$banner = &$lstBanner[$i];
					$link = site_url('breview/detail/' . $filter . '/' . $banner['bannerid']);
				?>

				<tr>
					<td>
						<p class="brv-stt">
							<?php echo $i + 1;?>
						</p>
					</td>
					
					<td>
						<p class="brv-img">
							<img src="<?php echo $banner['filename'];?>" border="0" width="90" height="90" />
						</p>
					</td>
					
					<td>
						<div class="brv-title">
							<?php echo $banner['title'];?>
						</div>
					</td>
					
					<td>
						<div class="brv-content">
							<?php echo $banner['content'];?> 
						</div>
					</td>
					
					<td>
						<p class="brv-url">
							<a href="<?php echo $banner['url'];?>" target="_blank">
							<?php echo $banner['url'];?>
							</a>
						</p>
					</td>
					
					<td>
						<p class="brv-campaign">
							<?php echo $banner['campaignname'];?>
						</p>
					</td>
					
					<td>
						<p class="brv-user">
							<?php echo $banner['username'];?>
						</p>
					</td>
					
					<td>
						<p class="brv-status">
							<?php echo ($banner['notifyed']==1?$lang['b_koduyet']:($banner['notifyed']==2?$lang['b_daduyet']:$lang['b_taomoi']));?>
						</p>
					</td>
					
					<td>
						<p class="brv-chk">
							<?php if ($banner['notifyed']!=2){?>
							<input type="checkbox" name="cbbreview[]" value="<?php echo $banner['bannerid'];?>" />
							<?php }?>
						</p>
					</td>
					
				</tr>
				
				<?php } //--> end for?>
				
			</table>
			<input type="hidden" id="breview_status" name="status" value="" />
			</form>
			<!-- paging -->
			<div class="myclear martop20">
				<div class="brv-paging-left">
					<table class="tbl-list brv-paging" border="1">
						<tr>
							<td class="brv-paging-name">
								<?php echo $lang['b_page'].' '. $page.' ['.$total_page.']'?>
							</td>
							
							<td class="brv-paging-pre-next">
								<img class="brv-img-pre" alt="previous" src="/images/imgpre.gif" onclick="goPage(<?php echo $page > 1 ? $page - 1 : $page;?>)" />
								<img class="brv-img-next" alt="next" src="/images/imgnext.gif" onclick="goPage(<?php echo $page + 1;?>)" />
							</td>
							
							<td class="brv-paging-num-item">
								<select onchange="slcLimitChange(this.value);">
									<option value="10" <?php if($limit == 10) echo 'selected';?>>10</option>
									<option value="20" <?php if($limit == 20) echo 'selected';?>>20</option>
									<option value="50" <?php if($limit == 50) echo 'selected';?>>50</option>
								</select>
							</td>
						</tr>
					</table>
				</div>
				<!-- Popup -->
				<div id="option3" class="checkout-form-card padtop20 padbottom20" style="display:none">
					<div id="pay-mess"></div>
					<p class="login-label">
						<?php echo $lang['add_publisher']?> ?
					</p>
					<p class="padbottom2">
						<select name="lstPublisher" id="lstPublisher" multiple="multiple" style="width:300px;height:150px;border:1px solid #ddd">
						<?php foreach ($publishers as $item){?>
							<option value="<?php echo $item['user_id']?>" title="<?php echo $item['username']?>">
								<?php echo $item['username']?>
							</option>
						<?php }?>
						</select>
					</p>
					
					<p class="login-label padtop10">
						<input type="button" value="<?php echo $lang['b_ok']?>" onclick="changePublisher();" />
						<input type="button" value="<?php echo $lang['b_cancel']?>" onclick="$('#mask,#option3').hide();" />
						&nbsp;<img id="loading" src="/images/ajaxLoading.gif" border="0" style="display:none" />
					</p>
				</div>
				<div id="mask"></div>
				<!-- // Popup -->
				<div class="brv-paging-right">
					<table class="float-right">
						<tr>
							<td>
								<input type="button" value="<?php echo $lang['add_publisher']?>" onclick="breviewSubmit();" />
							</td>
						</tr>
					</table>
				</div>
				
				<!-- important. fix for ie 6. Don't remove -->
				<!--[if IE 6]><br class="clearboth" /><![endif]-->
			</div>
			<!-- end paging -->
			
		</div>
	</div> <!-- end page content -->

<script type="text/javascript">
	function slcFilterChange()
	{
		var url = '<?php echo site_url('breview/review'); ?>';
		var slFilter = $('#slcFilter').val();
		var slUid = $('#slcPublisher').val();
		window.location = url + '/filter/' + slFilter + '/uid/' + slUid;
	}
	function slcLimitChange(strVal)
	{
		<?php
		$uri = $this->uri->ruri_to_assoc(1);
		if(array_key_exists('limit',$uri)) unset($uri['limit']);
		echo "var url = '".base_url().$this->uri->assoc_to_uri($uri)."';\n";
		?>
		window.location = url + '/limit/' + strVal;
	}
	function goPage(strVal)
	{
		<?php
		$uri = $this->uri->ruri_to_assoc(1);
		if(array_key_exists('page',$uri)) unset($uri['page']);
		echo "var url = '".base_url().$this->uri->assoc_to_uri($uri)."';\n";
		?>
		window.location = url + '/page/' + strVal;
	}
	function chkReviewChange()
	{
		var _value = $('#chkAll:checked').val() == 'on' ? true : false;
		$('input:checkbox[name="cbbreview[]"]').each(function(index){
			$(this).attr('checked', _value);
		});
	}
	function breviewSubmit()
	{
		if($('input:checkbox[name="cbbreview[]"]').filter(':checked').length <= 0)
		{
			alert('<?php echo $lang['please_select_item']?>');
			return;
		}

		Popup('option3');
	}

	function Popup(id) { 
		 
		$('#pay-mess').html('');
		id = '#' + id;
	    //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();
     
        //Set height and width to mask to fill up the whole screen
        $('#mask').css({'width':maskWidth,'height':maskHeight});
         
        //transition effect    
        $('#mask').fadeIn(300);   
        $('#mask').fadeTo("fast",0.8); 
     
        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();
               
        //Set the popup window to center
        $(id).css('top',  winH/2-$(id).height()/2 + $(window).scrollTop());
        $(id).css('left', winW/2-$(id).width()/2);
     
        //transition effect
        $(id).fadeIn(300);

        //if mask is clicked
        $('#mask').click(function () {
            $(this).hide();
            $(id).hide();
        });  
	}

	function changePublisher()
	{
		var n = $('input:checkbox[name="cbbreview[]"]:checked').length;
		if(n == 0) return;
		
		var str = new Array(n);
		var i = 0;
		$('input:checkbox[name="cbbreview[]"]:checked').each(function(){
			str[i] = $(this).val(); i++;
		});

		var pubid = $('#lstPublisher').val();
		if(pubid == null || pubid == '' || pubid == 'undefined')
		{
			$('#pay-mess').html('<?php echo $lang['enter_add_publisher']?>');
			return;
		}

		$('#loading').fadeIn('fast');
		$.ajax({
			type: 'POST',
			url: '<?php echo site_url('breview/change_publisher')?>',
			data: {uid: pubid, banner: str.join(',')},
			success: function(data){
				$('#loading').fadeOut('fast');
				$('#pay-mess').html(data);
				setTimeout("$('#mask, #option3').hide();$('#pay-mess').html('');", 2000);
				window.location.reload(true);
			}
		});
	}
</script>